package ui.tui;

import java.util.Properties;

/**
 * @autor Piesold
 */
public class OutputHelper {

	public static String strFill( String toFill, int toLen, char signToUse, boolean addOnEnd ) {

		StringBuffer sb = new StringBuffer();

		for (int i = 0; i < toLen-toFill.length(); i++) { sb.append( signToUse ); }

		if ( addOnEnd )
			toFill += sb.toString();
		else
			toFill = sb.toString() + toFill;

		return toFill;

	}

	/**
	 * strTrimToSize
	 * @param theString
	 * @param newSize
	 * @return
	 */
	public static String stts( String theString, int newSize ) {
		return ( theString.length() < newSize ) ? strFill(theString, newSize, ' ', true ) : theString.substring(0, newSize);
	}
	
	
	public static String carToString( Properties car ) {
		
		StringBuffer sb = new StringBuffer();
		
		sb.append( strFill( "Fahrgestellnummer :" , 20, ' ', true) ).append( car.getProperty( "car.number" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Fahrzeugtyp :" , 20, ' ', true) ).append( car.getProperty( "car.type" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Hersteller :" , 20, ' ', true) ).append( car.getProperty( "car.manufacturer" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Model :" , 20, ' ', true) ).append( car.getProperty( "car.model" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Farbe :" , 20, ' ', true) ).append( car.getProperty( "car.colour" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Motortyp :" , 20, ' ', true) ).append( car.getProperty( "car.enginetype" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Kilometerstand :" , 20, ' ', true) ).append( car.getProperty( "car.mileage" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Einkaufspreis :" , 20, ' ', true) ).append( car.getProperty( "car.originprice" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Verkaufspreis :" , 20, ' ', true) ).append( car.getProperty( "car.price" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Baujahr :" , 20, ' ', true) ).append( car.getProperty( "car.year" ) ).append( MenuBuilder.BR );
		sb.append( strFill( "Verkauft-Status :" , 20, ' ', true) ).append( car.getProperty( "car.isselled" ) ).append( MenuBuilder.BR );
				
		return sb.toString();
		
	}

}
